
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module oauth2client.crypt</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.crypt</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiclient-release/oauth2client/crypt.py">/home/jcgregorio/projects/apiclient-release/oauth2client/crypt.py</a></font></td></tr></table>
    <p><tt>#&nbsp;-*-&nbsp;coding:&nbsp;utf-8&nbsp;-*-<br>
#<br>
#&nbsp;Copyright&nbsp;(C)&nbsp;2011&nbsp;Google&nbsp;Inc.<br>
#<br>
#&nbsp;Licensed&nbsp;under&nbsp;the&nbsp;Apache&nbsp;License,&nbsp;Version&nbsp;2.0&nbsp;(the&nbsp;"License");<br>
#&nbsp;you&nbsp;may&nbsp;not&nbsp;use&nbsp;this&nbsp;file&nbsp;except&nbsp;in&nbsp;compliance&nbsp;with&nbsp;the&nbsp;License.<br>
#&nbsp;You&nbsp;may&nbsp;obtain&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;License&nbsp;at<br>
#<br>
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>
#<br>
#&nbsp;Unless&nbsp;required&nbsp;by&nbsp;applicable&nbsp;law&nbsp;or&nbsp;agreed&nbsp;to&nbsp;in&nbsp;writing,&nbsp;software<br>
#&nbsp;distributed&nbsp;under&nbsp;the&nbsp;License&nbsp;is&nbsp;distributed&nbsp;on&nbsp;an&nbsp;"AS&nbsp;IS"&nbsp;BASIS,<br>
#&nbsp;WITHOUT&nbsp;WARRANTIES&nbsp;OR&nbsp;CONDITIONS&nbsp;OF&nbsp;ANY&nbsp;KIND,&nbsp;either&nbsp;express&nbsp;or&nbsp;implied.<br>
#&nbsp;See&nbsp;the&nbsp;License&nbsp;for&nbsp;the&nbsp;specific&nbsp;language&nbsp;governing&nbsp;permissions&nbsp;and<br>
#&nbsp;limitations&nbsp;under&nbsp;the&nbsp;License.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="base64.html">base64</a><br>
<a href="OpenSSL.crypto.html">OpenSSL.crypto</a><br>
</td><td width="25%" valign=top><a href="hashlib.html">hashlib</a><br>
<a href="logging.html">logging</a><br>
</td><td width="25%" valign=top><a href="json.html">json</a><br>
<a href="time.html">time</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#Signer">Signer</a>
</font></dt><dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#Verifier">Verifier</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#AppIdentityError">AppIdentityError</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="AppIdentityError">class <strong>AppIdentityError</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="oauth2client.crypt.html#AppIdentityError">AppIdentityError</a></dd>
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
<dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="AppIdentityError-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__init__">__init__</a>(...)&nbsp;initializes&nbsp;x;&nbsp;see&nbsp;x.__class__.__doc__&nbsp;for&nbsp;signature</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#AppIdentityError-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>

<hr>
Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><a name="AppIdentityError-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
&nbsp;<br>
Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>

<dl><dt><a name="AppIdentityError-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>

<dl><dt><a name="AppIdentityError-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__str__">__str__</a>()&nbsp;&lt;==&gt;&nbsp;str(x)</tt></dd></dl>

<dl><dt><a name="AppIdentityError-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>

<hr>
Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
</dl>
<dl><dt><strong>args</strong></dt>
</dl>
<dl><dt><strong>message</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Signer">class <strong>Signer</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Signs&nbsp;messages&nbsp;with&nbsp;a&nbsp;private&nbsp;key.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Signer-__init__"><strong>__init__</strong></a>(self, pkey)</dt><dd><tt>Constructor.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;pkey,&nbsp;OpenSSL.crypto.PKey,&nbsp;The&nbsp;private&nbsp;key&nbsp;to&nbsp;sign&nbsp;with.</tt></dd></dl>

<dl><dt><a name="Signer-sign"><strong>sign</strong></a>(self, message)</dt><dd><tt>Signs&nbsp;a&nbsp;message.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;message:&nbsp;string,&nbsp;Message&nbsp;to&nbsp;be&nbsp;signed.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;string,&nbsp;The&nbsp;signature&nbsp;of&nbsp;the&nbsp;message&nbsp;for&nbsp;the&nbsp;given&nbsp;key.</tt></dd></dl>

<hr>
Static methods defined here:<br>
<dl><dt><a name="Signer-from_string"><strong>from_string</strong></a>(key, password<font color="#909090">='notasecret'</font>)</dt><dd><tt>Construct&nbsp;a&nbsp;<a href="#Signer">Signer</a>&nbsp;instance&nbsp;from&nbsp;a&nbsp;string.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;key:&nbsp;string,&nbsp;private&nbsp;key&nbsp;in&nbsp;P12&nbsp;format.<br>
&nbsp;&nbsp;password:&nbsp;string,&nbsp;password&nbsp;for&nbsp;the&nbsp;private&nbsp;key&nbsp;file.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;<a href="#Signer">Signer</a>&nbsp;instance.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;OpenSSL.crypto.Error&nbsp;if&nbsp;the&nbsp;key&nbsp;can't&nbsp;be&nbsp;parsed.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Verifier">class <strong>Verifier</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Verifies&nbsp;the&nbsp;signature&nbsp;on&nbsp;a&nbsp;message.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Verifier-__init__"><strong>__init__</strong></a>(self, pubkey)</dt><dd><tt>Constructor.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;pubkey,&nbsp;OpenSSL.crypto.PKey,&nbsp;The&nbsp;public&nbsp;key&nbsp;to&nbsp;verify&nbsp;with.</tt></dd></dl>

<dl><dt><a name="Verifier-verify"><strong>verify</strong></a>(self, message, signature)</dt><dd><tt>Verifies&nbsp;a&nbsp;message&nbsp;against&nbsp;a&nbsp;signature.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;message:&nbsp;string,&nbsp;The&nbsp;message&nbsp;to&nbsp;verify.<br>
&nbsp;&nbsp;signature:&nbsp;string,&nbsp;The&nbsp;signature&nbsp;on&nbsp;the&nbsp;message.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;True&nbsp;if&nbsp;message&nbsp;was&nbsp;singed&nbsp;by&nbsp;the&nbsp;private&nbsp;key&nbsp;associated&nbsp;with&nbsp;the&nbsp;public<br>
&nbsp;&nbsp;key&nbsp;that&nbsp;this&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;was&nbsp;constructed&nbsp;with.</tt></dd></dl>

<hr>
Static methods defined here:<br>
<dl><dt><a name="Verifier-from_string"><strong>from_string</strong></a>(key_pem, is_x509_cert)</dt><dd><tt>Construct&nbsp;a&nbsp;Verified&nbsp;instance&nbsp;from&nbsp;a&nbsp;string.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;key_pem:&nbsp;string,&nbsp;public&nbsp;key&nbsp;in&nbsp;PEM&nbsp;format.<br>
&nbsp;&nbsp;is_x509_cert:&nbsp;bool,&nbsp;True&nbsp;if&nbsp;key_pem&nbsp;is&nbsp;an&nbsp;X509&nbsp;cert,&nbsp;otherwise&nbsp;it&nbsp;is<br>
&nbsp;&nbsp;&nbsp;&nbsp;expected&nbsp;to&nbsp;be&nbsp;an&nbsp;RSA&nbsp;key&nbsp;in&nbsp;PEM&nbsp;format.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;<a href="#Verifier">Verifier</a>&nbsp;instance.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;OpenSSL.crypto.Error&nbsp;if&nbsp;the&nbsp;key_pem&nbsp;can't&nbsp;be&nbsp;parsed.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-make_signed_jwt"><strong>make_signed_jwt</strong></a>(signer, payload)</dt><dd><tt>Make&nbsp;a&nbsp;signed&nbsp;JWT.<br>
&nbsp;<br>
See&nbsp;<a href="http://self-issued.info/docs/draft-jones-json-web-token.html">http://self-issued.info/docs/draft-jones-json-web-token.html</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;signer:&nbsp;crypt.<a href="#Signer">Signer</a>,&nbsp;Cryptographic&nbsp;signer.<br>
&nbsp;&nbsp;payload:&nbsp;dict,&nbsp;Dictionary&nbsp;of&nbsp;data&nbsp;to&nbsp;convert&nbsp;to&nbsp;JSON&nbsp;and&nbsp;then&nbsp;sign.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;string,&nbsp;The&nbsp;JWT&nbsp;for&nbsp;the&nbsp;payload.</tt></dd></dl>
 <dl><dt><a name="-verify_signed_jwt_with_certs"><strong>verify_signed_jwt_with_certs</strong></a>(jwt, certs, audience)</dt><dd><tt>Verify&nbsp;a&nbsp;JWT&nbsp;against&nbsp;public&nbsp;certs.<br>
&nbsp;<br>
See&nbsp;<a href="http://self-issued.info/docs/draft-jones-json-web-token.html">http://self-issued.info/docs/draft-jones-json-web-token.html</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;jwt:&nbsp;string,&nbsp;A&nbsp;JWT.<br>
&nbsp;&nbsp;certs:&nbsp;dict,&nbsp;Dictionary&nbsp;where&nbsp;values&nbsp;of&nbsp;public&nbsp;keys&nbsp;in&nbsp;PEM&nbsp;format.<br>
&nbsp;&nbsp;audience:&nbsp;string,&nbsp;The&nbsp;audience,&nbsp;'aud',&nbsp;that&nbsp;this&nbsp;JWT&nbsp;should&nbsp;contain.&nbsp;If<br>
&nbsp;&nbsp;&nbsp;&nbsp;None&nbsp;then&nbsp;the&nbsp;JWT's&nbsp;'aud'&nbsp;parameter&nbsp;is&nbsp;not&nbsp;verified.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;dict,&nbsp;The&nbsp;deserialized&nbsp;JSON&nbsp;payload&nbsp;in&nbsp;the&nbsp;JWT.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;<a href="#AppIdentityError">AppIdentityError</a>&nbsp;if&nbsp;any&nbsp;checks&nbsp;are&nbsp;failed.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>AUTH_TOKEN_LIFETIME_SECS</strong> = 300<br>
<strong>CLOCK_SKEW_SECS</strong> = 300<br>
<strong>MAX_TOKEN_LIFETIME_SECS</strong> = 86400</td></tr></table>
</body></html>